package com.ruoyi.project.cms.sa.order.maintain.controller;

import com.ruoyi.common.constant.CMSConstants;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.cms.sa.order.maintain.domain.Order;
import com.ruoyi.project.cms.sa.order.maintain.domain.OrderVO;
import com.ruoyi.project.cms.sa.order.maintain.service.IOrderService;
import com.ruoyi.project.cms.sa.order.type.domain.Type;
import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：MrL
 * 时间：2020-05-20
 */
@Controller
@RequestMapping("/cms/sa/order")
public class OrderController extends BaseController {

    // 当前控制类的请求地址前缀
    private String prefix = "cms/sa/order";

    @Autowired
    private IOrderService orderService;

    @GetMapping()
    public String order() {
        return prefix + "/order";
    }

    /**
     * 根据搜索条件分页查询订单信息
     * @param orderVO
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderVO orderVO) {
        System.out.println(orderVO);
        startPage();
        List<OrderVO> list = orderService.selectOrderList(orderVO);
        System.out.println(list);
        return getDataTable(list);
    }

    /**
     * 修改订单信息
     */
    @GetMapping("/edit/{orderId}")
    public String edit(@PathVariable("orderId") Long orderId, ModelMap mmap) {
        // 根据类别ID查询订单类别信息
        mmap.put("name", "orderVO");
        mmap.put("orderVO", orderService.selectOrderById(orderId));
        return prefix + "/edit";
    }

    /**
     * 修改保存订单信息
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@Validated OrderVO orderVO) {
      /*  if (CMSConstants.ORDER_TYPE_NAME_NOT_UNIQUE.equals(typeService.checkTypeNameUnique(type))) {
            return error("修改类别'" + type.getTypeName() + "'失败，类别名称已存在");
        }*/
        return toAjax(orderService.updateOrderVO(orderVO));
    }

    /**
     * 查看订单信息详情
     *
     * @param orderId
     * @param mmap
     * @return
     */
    @GetMapping("/detail/{orderId}")
    public String detail(@PathVariable("orderId") Long orderId, ModelMap mmap) {
        mmap.put("name", "orderVO");
        mmap.put("orderVO", orderService.selectOrderById(orderId));
        return prefix + "/detail";
    }

}
